	
	var extensionOf = function(name){
		var d = name.lastIndexOf('.')+1;
		if(!d) return false;
		return name.substr(d).toLowerCase();
	}
		
	var FileObj = function(o){
		this.load = function(o){
			for(var k in o) this[k] = o[k];
			this.is_writable = this.perms[0]
			this.is_readable = this.perms[1];
			this.is_executable = this.perms[2];
		};
		this.load(o)
	}
	
	Smernel.observe('chrome:loaded', function(){
		Apps.filter = function(apps){
			var a = {}
			for(var k in apps){
				var f = apps[k];
				if(!f.perms[0]) continue;
				if(!Dir.showdots && (f.basename.substr(0, 1) == '.')) continue;
				if(f['class'] != 'app') f.modpath = 'Fmgr/0.4';
				a[k] = f;
			}
			return a;
		}
	});
	
	Smernel.observe('browser:loaded', function(){
		AppsB.filter = function(apps){
			var a = {}
			for(var k in apps){
				var f = apps[k];
				if(!f.perms[0]) continue;
				switch(Browser.task){
					case 'savefile':
						switch(true){
							case (f.id == File.id):
								f.highlighted = true;
								break;
							case ((f.dir == 1)&&(f['class'] != 'Trash')):
							case (f['class'] == File['class']):
							case ((f.mime.split('/')[0] == File.mime.split('/')[0]) && (f['class'] != 'htaccess')):
								break;
							default:
								f.disabled = true;	
						}
					break;
					case 'link':
						switch(true){
							case (f.id == File.id):
								f.highlighted = true;
								break;
							case ((f.dir == 1)&&(f['class'] != 'Trash')):
							case ((f.mime.split('/')[0] == 'text') && (f['class'] != 'htaccess')):
								break;
							default:
								f.disabled = true;	
						}
					break;
				}
				if(f['class'] != 'app') f.modpath = 'Fmgr/0.4';
				a[k] = f;
			}
			return a;
		}									   
		
											   
		AppsB.clickHandler = function(){
			switch(1){
				case (this.dir):
					Browser.proceedto(this.rel)
					return;
				default:
					switch(Browser.task){
						case 'savefile':
							Browser.inp.value = this.basename;
							Browser.victim = this.fmrp;
							TUXconfirm('Overwrite ' + this.basename + '?', function(a){
								if(!a) return (Browser.inp.value = File.basename);
								File.saveTo(Browser.location, Browser.inp.value, Browser.victim);																					
							});
							break;
						case 'link':
							if(Browser.inp.value == this.fmrp) File.doLink(this.id);
							Browser.inp.value = this.fmrp;
					}
			}
		}
	});
	
	var Fmgr = {
		run:function(){
			this.script = $('Fmgr.js').src;
			this.path = this.script.substring(0, this.script.lastIndexOf('/')+1);
			var q = this.script.lastIndexOf('?');
			if(q != -1) this.script.substr(q+1).split(',').each(function(s){ 
				Fmgr.include(s + '.js');
			});
		},
		include:function(s, f){
			document.include(Fmgr.path + s, f);
		}
	}
	
	Fmgr.run();